package com.onpositive.page.core;

import org.eclipse.jface.text.Document;

import com.onpositive.page.core.wikihelper.DocumentWrapper;
import com.onpositive.page.core.wikihelper.FontStyleManager;
import com.onpositive.page.core.wikihelper.WebImageManager;
import com.onpositive.page.core.wikihelper.WebLayerManager;
import com.onpositive.richtext.model.BasePartitionLayer;
import com.onpositive.richtexteditor.io.ModelBasedLineInformationProvider;
import com.onpositive.richtexteditor.io.html.HTMLSerializer;
import com.onpositive.richtexteditor.model.ISimpleRichTextModel;
import com.onpositive.richtexteditor.wikitext.io.DefaultWikitextLoader;

public class DefaultPage implements IPage {

	IGenericSiteInfo siteInfo;
	NamedLink url;
	String content;

	public DefaultPage(IGenericSiteInfo siteInfo, NamedLink namedLink) {
		super();
		this.siteInfo = siteInfo;
		this.url = namedLink;
	}

	String keyWords;

	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}

	
	public IGenericSiteInfo getInfo() {
		return siteInfo;
	}

	
	public String getKeyWords() {
		return keyWords;
	}


	public NamedLink getUrl() {
		return url;
	}


	public String getRenderedContent() {
		DocumentWrapper d = new DocumentWrapper(new Document());
		ISimpleRichTextModel parse = new DefaultWikitextLoader(d)
				.parse(content);
		ModelBasedLineInformationProvider modelBasedLineInformationProvider = new ModelBasedLineInformationProvider(parse);
		BasePartitionLayer basePartitionLayer = new BasePartitionLayer();
		basePartitionLayer.getStorage().setPartitions(parse.getPartitions());
		WebLayerManager l=new WebLayerManager(d, new FontStyleManager(), new WebImageManager(),basePartitionLayer);		
		basePartitionLayer.setManager(l);
		HTMLSerializer s = new HTMLSerializer(basePartitionLayer, d,modelBasedLineInformationProvider);
		return s.serializeAllToStr();		
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public ITheme getTheme() {
		return siteInfo.getTheme();
	}
}
